/**
 * 
 */
package ru.amse.stroganova.ui.command;

import ru.amse.stroganova.presentation.EdgePresentation;
import ru.amse.stroganova.ui.visual.GraphElementSelection;

class WeightChangeCommand implements Command {
	
	private final GraphElementSelection graphSelection;

	private final int oldWeight;

	private final int newWeight;

	private final EdgePresentation edge;

	/**
	 * Creates new WeightChangeCommand.
	 * 
	 * @param oldWeight
	 *            old weight
	 * @param newWeight
	 *            new weight
	 * @param edge edge changing
	 * @param graphSelection 
	 */
	public WeightChangeCommand(int oldWeight, int newWeight, EdgePresentation edge, GraphElementSelection graphSelection) {
		this.graphSelection = graphSelection;
		this.oldWeight = oldWeight;
		this.newWeight = newWeight;
		this.edge = edge;
	}

	public void execute() {
		graphSelection.unselect();
		edge.setWeight(newWeight);
		graphSelection.selectEdge(edge);
	}

	public void undo() {
		graphSelection.unselect();
		edge.setWeight(oldWeight);
		graphSelection.selectEdge(edge);
	}

}